/**
 * 订单
 * @author 康文程
 * @date 2024-1-9
 */
class Orders {
    /**
     * 新增订单
     * @param longitude 目前纬度
     * @param latitude 目前经度
     * @param totalQuantity 商品件数
     * @param totalPrice 应付价格
     * @param freight 运费
     * @param informationId 用户Id
     * @param couponCredit 优惠卷抵扣价格
     * @param couponId 优惠卷Id
     * @param quantity 商品数量
     * @return {Promise<int>} 订单号
     */
    addOrders(longitude,latitude,totalQuantity,totalPrice,freight,informationId,couponCredit,couponId,quantity){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/add/order",
                method: "POST",
                data: {
                    longitude: longitude,
                    latitude : latitude,
                    totalQuantity : totalQuantity,
                    totalPrice : totalPrice,
                    freight : freight,
                    couponCredit : couponCredit,
                    informationId : informationId,
                    couponId : couponId,
                    quantity : quantity
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }

    /**
     * 查询订单还有多久过期
     * @param orderId 订单Id
     * @return {Promise<int>} 分钟
     */
    getOrderExpirationTimeByAddressId(orderId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/order/expires/date",
                method: "GET",
                data: {
                    orderId: orderId,
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    updateOrderStatusByOrderId(orderId){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/modify/order/status",
                method: "POST",
                data: {
                    orderId: orderId,
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
}